package h0802;

import java.util.Scanner;

/**
  * @description 字符串序列判定
  * @author 不知名帅哥
  * @date 2024/8/2 12:36
  * @version 1.0
*/
public class StringSequenceDetermination {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s = sc.nextLine();
        String l = sc.nextLine();

        sc.close();
        System.out.println(getLastIndex(l, s));
    }

    private static int getLastIndex(String l, String s) {
        int i=0;
        int j=0;
        while (j< l.length()&&i< s.length()){
            char c = s.charAt(i);
            char h= l.charAt(j);
            if (c==h){
                if (i==s.length()-1){
                    return j;
                }
                i++;
            }
            j++;
        }
        //没找到
        return -1;
    }
}
